package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo6 {
    public static void main(String[] args) throws Exception {
        Class cls=Class.forName("reflect.Person");
        Method mtd=cls.getMethod("say",String.class,int.class);

        System.out.println(mtd.getName());//获取方法名

        System.out.println(mtd.getReturnType());//获取返回值类型
        System.out.println(mtd.getParameterCount());//获取参数个数
        Class[] types=mtd.getParameterTypes();//获取参数类型
        for (Class type:types){
            System.out.println(type);
        }
        int mod=mtd.getModifiers();//获取修饰符
        switch (mod){
            case Modifier.PUBLIC:
                System.out.println("public");
                break;
            case Modifier.PRIVATE:
                System.out.println("private");
                break;
            case Modifier.PROTECTED:
                System.out.println("protected");
                break;
            default:
                System.out.println("default");
        }
    }
}
